<?php

class Cat_Strings
{
	static function startsWith( $str, $seq, $caseSensitive = true )
	{
		$seqlen = mb_strlen( $seq );

		if ( mb_strlen( $str ) < $seqlen )
		{
			return false;
		}
		
		if ( $caseSensitive )
		{
			return ( mb_substr( $str, 0, $seqlen ) == $seq );
		}
		else
		{
			return ( mb_strtolower( mb_substr( $str, 0, $seqlen ) ) == mb_strtolower( $seq ) );			
		}
	}

	static function endsWith( $str, $seq, $caseSensitive = true )
	{
		$seqlen = mb_strlen( $seq );

		if ( mb_strlen( $str ) < $seqlen )
		{
			return false;
		}
		
		if ( $caseSensitive )
		{
			return ( mb_substr( $str, -1 * $seqlen ) == $seq );
		}
		else
		{
			return ( mb_strtolower( substr( $str, -1 * $seqlen ) ) == mb_strtolower( $seq ) );			
		}
	}
	
	static function ucfirst( $str )
	{
		$str = mb_strtolower( $str );
		$str = mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
		return $str;
	}
	
	static function camelize( $str, $sep = '' )
	{
		$arr = explode( "_", $str );		
		$arr = array_map( array( __CLASS__, 'ucfirst' ), $arr );		
		return implode( $sep, $arr );
	}
	
	static function classize( $str )
	{
		$str = str_replace( array( '.', '/', '\\' ), '_', $str );
		$str = self :: camelize( $str, '_' ); 
		return $str;
	} 
}

?>